 import { ref } from "vue";
 const defaultSize = 16
 export const fixMultiple:any = ref(1)
 export const autofontsize:any = ref(16)//字体大小
 export const autoFix = ()=>{
    let count = -1
    const   setScale = ()=>{
  const t:any = document.querySelector('body'),
   e = 1920,
    o = 945,
    d = parseFloat((e / o).toFixed(5)),
    a = parseFloat((window.innerWidth / window.innerHeight).toFixed(5)); 
    // if (a > d) { 
    //   const r = (window.innerHeight / o).toFixed(5); 
    //   t.style.transform = `scale(${r},${r}) translate(-50%,-50%)` 
    // } else { 
    //   const r = (window.innerWidth / e).toFixed(5); 
    //   t.style.transform = `scale(${r},${r}) translate(-50%,-50%)` 
    // }
    const r = (window.innerHeight / o).toFixed(5); 
    const w:any = (window.innerWidth / e).toFixed(5); 
    fixMultiple.value = parseFloat(w).toFixed(1)
    
    if (fixMultiple.value<0.7) {
      fixMultiple.value = 0.7
    }else if(fixMultiple.value>1) {
      fixMultiple.value = 1
    }

    autofontsize.value = (defaultSize/fixMultiple).toFixed(1);
    t.style.setProperty('--auto-fontSize', autofontsize.value+'px');
    
    t.style.setProperty('--auto-fixMultiple', fixMultiple.value);
    t.style.transform = `scale(${w},${r}) translate(-50%,-50%)` 
  // document.querySelector('meta[name="viewport"]').setAttribute('content', `width=device-width, initial-scale=${r}`);
}
    window.addEventListener('resize', ()=>{
    if (count === window.devicePixelRatio||window.devicePixelRatio===1) {
      setScale()
    }else if (count===-1){
      count = window.devicePixelRatio
      setScale()
    }
    else{
      count = window.devicePixelRatio
    }
  });
  setScale()
 }

//  export default {
//   size,
//   autoFix
//  }